#include "mobilefilelistdelegate.h"
#include <QPainter>

#include "mobilefilelistview.h"

const int ITEM_LIST_MODE_WIDTH = 738;
const int ITEM_LIST_MODE_HEIGHT = 52;
const int ITEM_ICON_MODE_WIDTH = 96;
const int ITEM_ICON_MODE_HEIGHT = 96;

MobileFileListDelegate::MobileFileListDelegate(QAbstractItemView *parent) : KListViewDelegate(parent) {}

MobileFileListDelegate::~MobileFileListDelegate() {}

QSize MobileFileListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(index);
    auto *listView = qobject_cast<const MobileFileListView *>(option.widget);

    if (listView->viewMode() == QListView::IconMode) {
        return QSize(ITEM_ICON_MODE_WIDTH, ITEM_ICON_MODE_HEIGHT);
    } else {
        QFont font; //获取系统字体大小
        font = QApplication::font();
        QFontMetrics fm(font);
        int height = fm.height();

        return QSize(ITEM_LIST_MODE_WIDTH, height * 2 + 6);
//        return QSize(ITEM_LIST_MODE_WIDTH, ITEM_LIST_MODE_HEIGHT);
    }
}
